#include "comm.h"

int main()
{
    key_t key = ftok(PATH_NAME, PROJ_ID);
    if(key < 0){
        perror("ftok");
        return 1;
    }
    
    //client只需要获取即可，不需要创建
    int shmid = shmget(key, SIZE, IPC_CREAT);//单独使用IPC_CREAT，共享内存存在就获取，反之创建
    if(shmid < 0){
        perror("shmid");
        return 1;
    }
    printf("key: %u , shmid: %d\n", key, shmid);

    char* mem = (char*)shmat(shmid, NULL, 0);
    printf("client process attaches success\n");

    char c = 'A';
    while(c < 'Z'){
        mem[c - 'A'] = c;
        c++;
        mem[c - 'A'] = 0;
        sleep(2);
    }
    shmdt(mem);
    printf("client process detaches success\n");

    return 0;
}
